//
//  BlurViewController.swift
//  funcode
//
//  Created by Wan Jiading on 2017/2/24.
//  Copyright © 2017年 WanJiading. All rights reserved.
//

import UIKit

class BlurViewController: UIViewController, JDActionSheetDelegate {
	
	var currentSelectedIndex = -1
	
    override func viewDidLoad() {
        super.viewDidLoad()
		
		self.view.backgroundColor = UIColor.white
		setupControls()
    }
	
	override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
		
		setBlur()
	}
	
	func setupControls() {
		
		let imgView = UIImageView(image: UIImage(named: "blur_bg"))
		imgView.frame = self.view.bounds
		self.view.addSubview(imgView)
		
		
		
		let greenView = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 400))
		greenView.backgroundColor = UIColor.green
		greenView.layer.cornerRadius = 50
		greenView.center = self.view.center
		self.view.addSubview(greenView)
		
		let animation = CABasicAnimation.init(keyPath: "transform.rotation.z")
		animation.toValue = NSNumber.init(value: 2*Double.pi)
		animation.duration = 20.0
		animation.timingFunction = CAMediaTimingFunction.init(name: kCAMediaTimingFunctionLinear)
		animation.isCumulative = false
		animation.isRemovedOnCompletion = false
		animation.fillMode = kCAFillModeForwards
		animation.repeatCount = Float.greatestFiniteMagnitude

		greenView.layer.add(animation, forKey: nil)
		
	}
	
	func setBlur() {
		
		let sheet = JDActionSheet(title: "播放列表(4✋)", cancelTitle: "关闭", cycleName: "单曲循环", dataList: [Book()], delegate: self)
		sheet.currentSelectedIndex = currentSelectedIndex
		sheet.delegate = self
		sheet.show()
	
	}
	
	
	func actionSheet(_ actionSheet: JDActionSheet, indexDidClick: Int) {
		self.currentSelectedIndex = indexDidClick
		actionSheet.currentSelectedIndex = indexDidClick
		actionSheet.dismissSelf()
	}

}
